package com.scan.bus;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Pair;

import com.baidu.location.LocationClient;
import com.scan.bus.util.DeviceInfoUtil;
import com.scan.bus.util.LogUtil;
import com.scan.bus.util.SharedPrefUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.data.JPushConfig;
import cn.jpush.android.local.JPushAction;
import cn.jpush.android.service.JPushMessageReceiver;

public class MyApp extends Application {
    private static Context context;
    public static MyApp mApp;
    public LocationClient mLocationClient = null;
    public static String key = "79ef6707166953c847de5bf86d9657c7";

    public static boolean isSuccessResgiter = false;//是否注册成功别名
    /*
     * 支持设备列表
     */
    public static final Map<String, Pair<String, Integer>> sDevices;
    static {
        sDevices = new HashMap<>();
        sDevices.put("TPS508", new Pair<>("/dev/ttyACM0", 115200));
        sDevices.put("TPS360", new Pair<>("/dev/ttyACM0", 115200));
        sDevices.put("TPS537", new Pair<>("/dev/ttyACM0", 115200));
        sDevices.put("D2", new Pair<>("/dev/ttyHSL0", 9600)); // D2串口模式
        //sDevices.put("D2", new Pair<>("/dev/ttyACM0", 115200)); // D2U转串模式
        sDevices.put("TPS980", new Pair<>("/dev/ttyS0", 115200));
        sDevices.put("TPS980P", new Pair<>("/dev/ttyS0", 115200));
        sDevices.put("T20", new Pair<>("/dev/ttyS7", 115200));
        //sDevices.put("TPS980P", new Pair<>("/dev/ttyS0", 9600));
        sDevices.put("TPS530", new Pair<>("/dev/ttyUSB0", 115200));
    }

    @Override
    public void onCreate() {
        super.onCreate();
        try {
            mApp = this;
            context = getApplicationContext();
            JPushInterface.setDebugMode(true);
            JPushInterface.init(this);
            mLocationClient = new LocationClient(this);
            DeviceInfoUtil.getUniqueId(context);
//            getAndroidId(this);
        } catch (Exception e) {
        }
        if (mLocationClient != null) {

        }
    }

    public static Context getContext() {
        return context;
    }

    public static String getAndroidId(Context context) {
        String ANDROID_ID = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID);
        SharedPrefUtil.saveCacheSharedPrf("X-Device-ID", ANDROID_ID);
        return ANDROID_ID;
    }

    private JPushMessageReceiver jPushMessageReceiver = new JPushMessageReceiver() {
        @Override
        public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
            super.onAliasOperatorResult(context, jPushMessage);
            LogUtil.httpLogW("onAliasOperatorResult: "+jPushMessage.getAlias());
            if (jPushMessage.getErrorCode() == 6002) {//超时处理


            }else {

                LogUtil.httpLogW("onAliasOperatorResult: "+jPushMessage.getErrorCode()+"");

            }

        }

    };

}
